﻿using MediatR;
using T.Materials.API.Application.Command.MaterialStoreCommand;
using T.Materials.Domain.Model;
using T.Materials.Repository.MaterialsInterface;

namespace T.Materials.API.Application.CommandHandler.MaterialStoreCommandHandler
{
    /// <summary>
    /// 物资与入库修改命令处理器
    /// </summary>
    public class UpdateMaterialStoreCommandHandler : IRequestHandler<UpdateMaterialStoreCommand, int>
    {
        /// <summary>
        /// 物资与入库仓储接口
        /// </summary>
        protected readonly IMaterialStoreRepository materialStoreRepository;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="materialStoreRepository">物资与入库仓储接口</param>
        public UpdateMaterialStoreCommandHandler(IMaterialStoreRepository materialStoreRepository)
        {
            this.materialStoreRepository = materialStoreRepository;
        }

        /// <summary>
        /// 更新物资与入库信息
        /// </summary>
        /// <param name="request">请求参数</param>
        /// <param name="cancellationToken">取消标记</param>
        /// <returns>返回受影响的行数</returns>
        public async Task<int> Handle(UpdateMaterialStoreCommand request, CancellationToken cancellationToken)
        {
            return await materialStoreRepository.UpdateAsync(new MaterialStore()
            {
                MaterialStoreId = request.MaterialStoreId,
                CompanyID = request.CompanyID,
                User_Id = request.User_Id,
                NameOfGoods = request.NameOfGoods,
                MaterialStoreType = request.MaterialStoreType,
                Material = request.Material,
                Specifications = request.Specifications,
                CountryId=request.CountryId,
                EconomizeId=request.EconomizeId,
                Number = request.Number,
                DeliveryDate = request.DeliveryDate,
                UsageDescription = request.UsageDescription,
                Applicant = request.Applicant,
                ApprovalStatus = request.ApprovalStatus,
                Approver = request.Approver,
                Registrant = request.Registrant,
                PaymentMethod = request.PaymentMethod,
                UnitPrice = request.UnitPrice,
                Notes = request.Notes,
                MaterialClassificat = request.MaterialClassificat,
                UpdatedBy = request.UpdatedBy,
                UpdatedDate = DateTime.Now
            });
        }
    }
}
